package com.yx1996.utils;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public  class HibernateUtils {
    private static SessionFactory sf;

    static {
        //创建configuration对象
        Configuration configuration = new Configuration().configure();
        //创建sessfactory对象
        sf = configuration.buildSessionFactory();
    }

    //获得新session
    public static Session openSession() {
        Session session = sf.openSession();
        return session;
    }

    //获得线程绑定的session
    public static Session getCurrentSession() {
        Session session = sf.getCurrentSession();
        return session;
    }


}
